package com.yt.demo.controller;

import com.yt.demo.dto.BaseResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/client")
@Slf4j
public class HelloController {
    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/testRibbon")
    public BaseResp<String> testRibbon(@RequestParam("param") String param) {
        String url = "http://demo-hello/hello/testRibbon?param=" + param;

        // 直接调用十次
        for (int i = 0; i < 10; i++) {
            BaseResp<?> resp = restTemplate.getForObject(url, BaseResp.class);
            log.info("i-{}: {}", i, resp);
        }
        return BaseResp.success(null);
    }
}
